//
// Description: 415. 字符串相加
// Created by Loading on 2022/5/3.
//

#include <bits/stdc++.h>

using namespace std;

string addStrings(string num1, string num2) {
    string res;
    int i = (int) num1.size() - 1;
    int j = (int) num2.size() - 1;
    // 进位
    int carry = 0;
    while (i >= 0 || j >= 0 || carry != 0) {
        int x1 = i >= 0 ? num1[i] - '0' : 0;
        int x2 = j >= 0 ? num2[j] - '0' : 0;
        int sum = x1 + x2 + carry;
        res.push_back('0' + sum % 10);
        carry = sum / 10;
        --i;
        --j;
    }
    reverse(res.begin(), res.end());

    return res;
}

int main() {
    string num1 = "9999";
    string num2 = "1111";
    auto res = addStrings(num1, num2);
    cout << res << endl;

    return 0;
}